{% extends "base.html" %}
{% block title %}Success{% endblock %}
{% block main %}
    <div class="container" style="height: 80%">
        <div class="row container col-6 offset-3 align-content-center" style="height: 40%">
            <span class="h4 text-center" style="height: 20%">实验报告生成完毕，点击下方按钮查看</span>
        </div>

        <div class="row container col-2 offset-5">
            <button class="btn-dark" id="btn" style="height: 30%">查看报告</button>
        </div>
    </div>
{% endblock %}
{% block script %}
    <script>
        let file_path = "";

        $(window).ready(() => {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "{{ url_for('rest.get_report_path') }}",
                data: {},
                success: (result) => {
                    console.log(result);
                    file_path = result["result"];
                },
                error: (result) => {
                    console.log(result);
                }
            });
        });

        $("#btn").click(() => {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "{{ url_for('rest.open_file') }}",
                data: {
                    "file": file_path
                },
                success: (result) => {
                    console.log(result);
                },
                error: (result) => {
                    console.log(result);
                }
            });
        });
    </script>
{% endblock %}